<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/static/layui.js"></script>
    <link href="/static/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <input type="hidden" name="novel_id" value="{{book_id}}">
        <input type="hidden" name="chapter_id" value="{{chapter}}">
      <div class="layui-form-item">
        <label class="layui-form-label">单选框</label>
        <div class="layui-input-block">
            {% for item in sources %}
                <input type="radio" name="drive_id" value="{{ item.id }}" title="{{ item.drive_name }}--{{ item.chapter }}" {% if item.drive_name == now_source %}checked{% endif %}>
            {% endfor %}
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">切换</button>
        </div>
      </div>
    </form>
</body>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/jquery.cookie.js"></script>
<script src="/static/js/base.js"></script>
<script>
    layui.use(['form', 'laydate', 'util'], function() {
        var form = layui.form;
        var layer = layui.layer;

        // 提交事件
        form.on('submit(demo1)', function (data) {
            var field = data.field; // 获取表单字段值
            $.post({
                url: "/novel/switchingSource",
                data: JSON.stringify(field),
                success: function (response, _){
                    alert(response.data);
                    if (response.code === 0){
                        // 刷新章节
                        get_menus(chapter_order);
                    }
                    parent.layer.closeAll();
                }
            });
            return false; // 阻止默认 form 跳转
        });
    });
</script>
</html>